package fr.afcepf.atod18.restaurants.web;

import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import fr.afcepf.atod18.restaurants.entity.Restaurant;
import fr.afcepf.atod18.restaurants.entity.TypeCuisine;
import fr.afcepf.atod18.restaurants.service.IGestionRestaurant;

@ManagedBean
@SessionScoped
public class RestaurantMB {
	private IGestionRestaurant gestionRestaurant;
	private Restaurant restaurant;
	private int idSelRestaurant;
	private boolean creation;
	
	private List<TypeCuisine> typesCuisine;
	private List<Restaurant> listeRestaurants;
	
	public List<Restaurant> getListeRestaurants() {
		return listeRestaurants;
	}

	public void setListeRestaurants(List<Restaurant> listeRestaurants) {
		this.listeRestaurants = listeRestaurants;
	}

	public boolean isCreation() {
		return creation;
	}

	public List<TypeCuisine> getTypesCuisine() {
		return typesCuisine;
	}

	public void setTypesCuisine(List<TypeCuisine> typesCuisine) {
		this.typesCuisine = typesCuisine;
	}

	public void setCreation(boolean creation) {
		this.creation = creation;
	}

	public Restaurant getRestaurant() {
		return restaurant;
	}

	public void setRestaurant(Restaurant restaurant) {
		this.restaurant = restaurant;
	}

	public int getIdSelRestaurant() {
		return idSelRestaurant;
	}

	public void setIdSelRestaurant(int idSelRestaurant) {
		this.idSelRestaurant = idSelRestaurant;
	}

	public IGestionRestaurant getGestionRestaurant() {
		return gestionRestaurant;
	}

	public void setGestionRestaurant(IGestionRestaurant gestionRestaurant) {
		this.gestionRestaurant = gestionRestaurant;
	}

	public RestaurantMB() {
		super();
		this.typesCuisine=gestionRestaurant.listerTypeCuisine();
		this.listeRestaurants=gestionRestaurant.listerRestaurant();
	}
	public String doNouveau(){
		restaurant = new Restaurant();
		creation=true;
		return null;
		
	}
	public String doSelection(){
		restaurant = gestionRestaurant.chercherRestaurant(idSelRestaurant);
		return null;
		
	}
	public String doSauve(){
		if (creation == true){gestionRestaurant.ajouterRestaurant(restaurant);}
		else{gestionRestaurant.modifierRestaurant(restaurant);}
		creation = false;
		return null;

	}
	public String doSupprime(){
		gestionRestaurant.supprimerRestaurant(restaurant);
		return null;
	}

	
}
